package com.hb.trade.server.project.opening.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.enums.OpeningBidTenderQueryEnum;
import com.hb.core.pojo.project.opening.dto.OpeningBidTenderDTO;
import com.hb.core.pojo.project.opening.entity.OpeningBidTender;
import com.hb.core.pojo.project.opening.mapper.OpeningBidTenderMapper;
import com.hb.trade.server.project.opening.service.OpeningBidTenderService;
import lombok.extern.slf4j.Slf4j;
import org.fzzn.core.model.enums.LogicEnum;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 开标大厅投标人记录Service实现类
 *
 * @author Lix1ang
 * @date 2022-2-17 17:06:38
 */
@Slf4j
@Service
public class OpeningBidTenderServiceImpl extends ServiceImpl<OpeningBidTenderMapper, OpeningBidTender> implements OpeningBidTenderService {


    @Override
    public OpeningBidTender getOpeningBidTenderBySection(OpeningBidTender openingBidTender) {
        return getOpeningBidTenderBySection(openingBidTender.getSectionId(), openingBidTender.getOrgId());
    }

    @Override
    public OpeningBidTender getOpeningBidTenderBySection(Long sectionId, Long orgId) {
        QueryWrapper<OpeningBidTender> wrapper = OpeningBidTender.wrapper();
        wrapper.eq("section_id", sectionId)
                .eq("org_id", orgId).last("limit 1");

        return getOne(wrapper);
    }

    @Override
    public List<String> listBidderNameBySectionId(Long sectionId) {
        return baseMapper.listBidderNameBySectionId(sectionId);
    }

    @Override
    public List<OpeningBidTender> listDecryptedBySectionId(Long sectionId) {
        QueryWrapper<OpeningBidTender> wrapper = OpeningBidTender.wrapper();
        wrapper.eq("section_id", sectionId)
                .eq("decrypt_flag", 1)
                .isNotNull("decrypt_content");
        List<OpeningBidTender> openingBidTenderList = baseMapper.selectList(wrapper);
        return openingBidTenderList;
    }

    /**
     * @Description: 查询未签章或确认的投标人 query 1 未签章 2 未确认
     *
     * @author yuezheng
     * @param openingBidTenderDTO
     * @return org.fzzn.core.model.msg.Message<java.util.List < com.hb.core.pojo.project.opening.entity.OpeningBidTender>>
     * @date 2022/6/20 16:49
     */
    @Override
    public List<OpeningBidTender> listByNotDecryptOrConfirm(OpeningBidTenderDTO openingBidTenderDTO) {
        QueryWrapper<OpeningBidTender> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OpeningBidTender::getOpeningBidInfoId, openingBidTenderDTO.getOpeningBidInfoId());
        if (openingBidTenderDTO.getQueryType().equals(OpeningBidTenderQueryEnum.DECRYPT.getCode())) {
            queryWrapper.lambda().eq(OpeningBidTender::getDecryptFlag, LogicEnum.NO.getCode());
        } else {
            queryWrapper.lambda().eq(OpeningBidTender::getConfirmFlag, LogicEnum.NO.getCode());
        }
        List<OpeningBidTender> list = this.baseMapper.selectList(queryWrapper);
        return list;
    }
}
